<!-- 产品管理 -->
<template>
  <div class="travel_manager">
    <el-container>
      <!-- <el-aside width="170px">
        <CategoryManager :config="categoryConfig" />
      </el-aside> -->
      <el-main class="base_main_content">
        <div class="base_screen_header">
          <span></span>
          <el-form :inline="true" class="base_search_form" @submit.prevent>
            <el-form-item>
              <el-select v-model="category" @change="searchCategory" placeholder="请选择分类" clearable>
                <el-option v-for="(item, index) in categoryOptions" :key="index" :label="item.label"
                  :value="item.value" />
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-select v-model="content" @change="searchContent" placeholder="请选择内容" clearable>
                <el-option v-for="(item, index) in contentOptions" :key="index" :label="item.label" :value="item.value" />
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-select v-model="targetarea" @change="searchTargetarea" placeholder="请选择目的地" clearable>
                <el-option v-for="(item, index) in targetareaOptions" :key="index" :label="item.label"
                  :value="item.value" />
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-select v-model="base" @change="searchBase" placeholder="请选择基地" clearable>
                <el-option v-for="(item, index) in baseOptions" :key="index" :label="item.label" :value="item.value" />
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-input v-model="name" @keyup[native].enter="searchName" @change="searchName" placeholder="产品名称" clearable
                :suffix-icon="Search" />
            </el-form-item>
          </el-form>
        </div>
        <StatusBar :data="statusList" :default="1" />
        <div class="base_main_header">
          <el-button type="primary" text @click="getExport">导出</el-button>
        </div>
        <TravelTable type="manager" route="travelmanager" @statusData="statusData" />
      </el-main>
    </el-container>
  </div>
</template>

<script setup>
import StatusBar from '@com/StatusBar.vue';
import TravelTable from '@com/travel/TravelTable.vue'
import CategoryManager from '@com/CategoryManager.vue';
import { ref, reactive } from 'vue'
import { Search } from '@element-plus/icons-vue'
import useRoute from "@util/router";
import travelConfigApi from "@api/travelConfig"
import api from "@api/travel"
import $ from "@util/base"

const route = useRoute()

const categoryConfig = {
  type: 'travel'
}

const targetarea = ref(route.query().target || '')
const category = ref(route.query().c || '')
const content = ref(route.query().content || '')

const baseOptions = ref([])
const categoryOptions = ref([])
const targetareaOptions = ref([])
const contentOptions = ref([])

getConfig()
function getConfig() {
  travelConfigApi.base(val => {
    baseOptions.value = val
  })
  travelConfigApi.category(val => {
    categoryOptions.value = val
  })
  travelConfigApi.targetarea(val => {
    targetareaOptions.value = val
  })
  travelConfigApi.content(val => {
    contentOptions.value = val
  })
}

const base = ref(route.query().base || '')
const name = ref(route.query().name || '')

const statusList = reactive([{
  label: '全部',
  value: 1,
  total: 69
}, {
  label: '已上架',
  value: 3,
  total: 21
}, {
  label: '已下架',
  value: 2,
  total: 15
}])

function statusData(val) {
  statusList.forEach((e, i) => { e.total = val[i] })
}

function searchCategory(val) {
  route.replaceQuery('c', val)
}

function searchContent(val) {
  route.replaceQuery('content', val)
}

function searchTargetarea(val) {
  route.replaceQuery('target', val)
}

function searchBase(val) {
  route.replaceQuery('base', val)
}

function searchName(val) {
  route.replaceQuery('name', val)
}

function getExport() {
  let routeQuery = route.query()
  api.travelManagerExport({
    categoryCode: routeQuery.c,
    shopCode: routeQuery.base,
    name: routeQuery.name,
    status: routeQuery.status,
    targetArea: routeQuery.target,
    jointype: routeQuery.content,
  }, val => {
    $.download(val.url, "旅游产品导出")
  })
}
</script>

<style lang="scss"></style>